/**
 * Created by bestick on 2015/12/02.
 * 聚财邦首页函数库
 */
$(document).ready(function () {

    //缓存jquery选择器
    var $a_navbar_link = $('a.navbar-link');
    var $age = $('#age');
    var $term = $('#term');
    var $income = $('#income');
    var $save = $('#save');
    var $flowAsset = $('#flowAsset');
    var $level = $('#level');
    var $question_group_hidden = $('.question-group-hidden');

    /* =================================================== home nav =================================================== */

    //监听滚动
    $(window).scroll(function () {
        if (($(document).scrollTop() > 0) && ($(window).width() > 750)) {
            $('#nav').removeClass('navbar-away-top-padding').addClass('navbar-away-top-background');
        } else {
            $('#nav').addClass('navbar-away-top-padding').removeClass('navbar-away-top-background');
        }
    });

    //隐藏导航
    $(window).click(function () {
        $('#navbar-collapse').removeClass('in');
    });

    //产品点击后更改图标上下拉
    $a_navbar_link.click(function () {
        if ($a_navbar_link.next('.dropdown-menu').css('display') == 'none') {
            $('#navbar_product').next().removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
        } else {
            $('#navbar_product').next().removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
        }
    });

    //产品失去焦点后
    $a_navbar_link.blur(function () {
        $('#navbar_product').next().removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    });

    /* =================================================== home invest-risk-questionnaire =================================================== */

    //投资风险问卷调查input选中后的样式
    $('.question-group-input').bind({
        focus: function () {
            $(this).addClass('question-input-onfocus');
        },
        blur: function () {
            $(this).removeClass('question-input-onfocus');
        }
    });

    //age输入
    $age.bind('input propertychange', function () {
        $question_group_hidden.css('display', ($age.val() != '' && $term.val() != '') ? 'block' : 'none');
    });

    //期限菜单点击
    $('.question-group-term').click(function () {
        $term.val($(this).find('span').html());
        $question_group_hidden.css('display', ($age.val() != '' && $term.val() != '') ? 'block' : 'none');
    });

    //答题弹出菜单点击
    $('.question-group ul li a:not(:first)').click(function () {
        $(this).parents('.question-block').find('input.question-group-input:eq(1)').val($(this).find('span').html());
    });

    //提交风险问卷
    $('.btn-invest-risk-submit').click(function () {
        $('#question-group-form').submit();
    });
});